package com.ljx.blog.user.controller;

import com.ljx.blog.common.domain.vo.resp.ApiResult;
import com.ljx.blog.common.domain.vo.resp.PageResp;
import com.ljx.blog.security.annotation.ApiPermission;
import com.ljx.blog.security.common.PermissionConstant;
import com.ljx.blog.user.domain.entity.Tenant;
import com.ljx.blog.user.domain.vo.req.TenantPageReq;
import com.ljx.blog.user.domain.vo.req.TenantSubmitReq;
import com.ljx.blog.user.domain.vo.req.UserPageReq;
import com.ljx.blog.user.domain.vo.resp.TenantResp;
import com.ljx.blog.user.domain.vo.resp.UserResp;
import com.ljx.blog.user.service.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-10-12  15:16
 */
@Api(tags = "租户接口")
@RestController
@RequestMapping("/tenant")
public class TenantController {

    @Autowired
    private TenantService tenantService;

    @ApiOperation("获取主题信息")
    @GetMapping("/info/{id}")
    public ApiResult<TenantResp> getInfo(@PathVariable("id") Long tenantId){
        return ApiResult.success(tenantService.getInfo(tenantId));
    }


    @ApiOperation("根据租户code获取租户信息")
    @GetMapping("/code/{code}")
    public ApiResult<TenantResp> getInfoByCode(@PathVariable("code") String code){
        return ApiResult.success(tenantService.getInfoByCode(code));
    }

    @ApiPermission(permissions = {PermissionConstant.TENANT_NEW_EDIT, PermissionConstant.ADMIN_NEW_EDIT})
    @ApiOperation("创建/修改租户")
    @PostMapping("/submit")
    public ApiResult<TenantResp> submit(@Validated @RequestBody TenantSubmitReq req){
        return ApiResult.success(tenantService.submit(req));
    }

    @ApiPermission(permissions = {PermissionConstant.TENANT_LIST, PermissionConstant.ADMIN_LIST})
    @ApiOperation("获取租户分页")
    @GetMapping("/page")
    public ApiResult<PageResp<Tenant>> getPage(TenantPageReq req){
        return ApiResult.success(tenantService.getPage(req));
    }

}
